package com.scb.api.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "USERS", uniqueConstraints = { @UniqueConstraint(columnNames = "USER_SCREEN_NAME") })
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@XmlType(propOrder={"id", "name", "screenName", "description", "profileImage", "gender", "birthday", "url", "currentLocation", "createdAt"})
public class User {
	
	@Id
	@GenericGenerator(name = "generator", strategy = "increment")
    @GeneratedValue(generator = "generator")
	@Column(name = "USER_ID", unique = true, nullable = false)
	private Long id;
	
	@Column(name = "USER_NAME", nullable = false, length = 45)
	private String name;
	
	@Column(name = "USER_PASSWORD", nullable = false, length = 45)
	@XmlTransient
	private String password;
	
	@Column(name = "USER_LANGUAGE", nullable = false)
	@XmlTransient
	private String language;
	
	@Column(name = "USER_CREATED_AT", nullable = false)
	private Date createdAt;
	
	@Column(name = "USER_UPDATED_AT", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@XmlTransient
	private Date updatedAt;
	
	@Column(name = "USER_EMAIL", nullable = false, length = 100)
	@XmlTransient
	private String email;
	
	@Column(name = "USER_SCREEN_NAME", unique = true, nullable = false, length = 45)
	private String screenName;
	
	@Column(name = "USER_DESCRIPTION", length = 255)
	private String description;

	@Column(name = "USER_PROFILE_IMAGE", length = 255)
	private String profileImage;
	
	@Column(name = "USER_URL", length = 255)
	private String url;
	
	@Column(name = "USER_CURRENT_LOCATION", nullable = false)
	private String currentLocation;
	
	@Column(name = "USER_GENDER")
	private int gender;
	
	@Column(name = "USER_BIRTHDAY")
	@Temporal(TemporalType.DATE)
	private Date birthday;
	
	@Column(name = "USER_LAST_SIGN_IN_AT", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@XmlTransient
	private Date lastSignInAt;
	
	@Column(name = "USER_SIGN_IN_COUNT", nullable = false)
	@XmlTransient
	private int signInCount;
	
	@Column(name = "USER_MAILING_LIST", nullable = false)
	@XmlTransient
	private Boolean mailingList;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Date getUpdatedAt() {
		return updatedAt;
	}

	public void setUpdatedAt(Date updatedAt) {
		this.updatedAt = updatedAt;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getScreenName() {
		return screenName;
	}

	public void setScreenName(String screenName) {
		this.screenName = screenName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getProfileImage() {
		return profileImage;
	}

	public void setProfileImage(String profileImage) {
		this.profileImage = profileImage;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getCurrentLocation() {
		return currentLocation;
	}

	public void setCurrentLocation(String currentLocation) {
		this.currentLocation = currentLocation;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Date getLastSignInAt() {
		return lastSignInAt;
	}

	public void setLastSignInAt(Date lastSignInAt) {
		this.lastSignInAt = lastSignInAt;
	}

	public int getSignInCount() {
		return signInCount;
	}

	public void setSignInCount(int signInCount) {
		this.signInCount = signInCount;
	}

	public Boolean getMailingList() {
		return mailingList;
	}

	public void setMailingList(Boolean mailingList) {
		this.mailingList = mailingList;
	}
	
	//TODO: implement equals and hashCode
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
// 
//        ProductItem that = (ProductItem) o;
// 
//        if (getPk() != null ? !getPk().equals(that.getPk()) : that.getPk() != null) return false;
// 
//        return true;
//    }
// 
//    public int hashCode() {
//        return (getPk() != null ? getPk().hashCode() : 0);
//    }
}
